package com.androturka.saycolor;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class SayColor extends Activity {
	//Code Modified - 21.08.2011 22:41
	
    static final String TAG = "SayColor";
	int 			color;
    Button 			takePic;
	CameraManager 	cameraMan;
	ColorManager 	colorMan;
	ColorVocalist 	vocalist;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Log.i(TAG,"Application is Ready");
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
		cameraMan = new CameraManager();
		colorMan = new ColorManager();
        vocalist = new ColorVocalist( this );
		
		takePic = (Button)findViewById(R.id.takepicture);
        takePic.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Log.d(TAG,"Button Clicked");

				if ( CameraManager.takePicture() < 0 ){
					Log.e(TAG,"Cant Take Picture");
				}
				else{
					Log.d(TAG,"Picture is Taken Successfully");
					if ( (color = colorMan.getColor()) > 0)
						Log.e(TAG,"Cant Get Color");
					else {
						Log.d(TAG,"Color is Found " + color );
						if ( vocalist.vocalizeColor( color ) < 0 ) {	
							Log.e(TAG,"Cant Vocalize Color");						
						}
						else{
							Log.d(TAG,"Color is Vocalized SUCCESSFULLY");
						}
					}	
				}
			}
		});
    }
}